<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 层数最深叶子节点的和 -->
    <script>
      var deepestLeavesSum = function (root) {
        if (root == null) return 0
        let queue = [root]
        let sum = 0
        while (queue.length) {
          sum = 0
          let size = queue.length
          for (let i = 0; i < size; i++) {
            let cur = queue.shift()
            sum += cur.val
            if (cur.left) queue.push(cur.left)
            if (cur.right) queue.push(cur.right)
          }
        }
        // 现在就是最后一层的节点值和
        return sum
      }
      console.log(deepestLeavesSum([1, 2, 3, 4, 5, null, 6, 7, null, null, null, null, 8]))
    </script>
  </body>
</html>
